import com.khh.dao.BookDao;
import com.khh.entity.Book;
import com.khh.mapper.BookMapper;
import org.junit.Test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by webrx on 2017-08-25.
 */
public class Demo {

    @Test
    public void a(){


        BookDao bookDaos = new BookDao();
       /* int a = bookDaos.saves("<php>",20);
        System.out.println(a);*/
        List<Book> boks = bookDaos.queryall();
        for (Book b: boks) {
            System.out.println(b.getName()+"/-/-");
        }

        List<Book> bokss = bookDaos.sel();
        for (Book b: bokss) {
            System.out.println(b.getName()+"++");
        }

        BookDao book = new BookDao();

        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        String dates = format.format(new Date());
        Date d = new Date();
        book.ins("ios讲义",20, dates);

       /* BookDao books = new BookDao();
        int nn = books.inser("ios讲义",20, dates);
        System.out.println(nn);*/
    }

    @Test
    public void bb(){
        BookMapper sdao = new BookDao();
        int currpage = 10;
        int size = 2;
        int recordcount = sdao.getCount();
        int pagecount = recordcount%size==0 ? recordcount/size : recordcount/size+1;
        if(currpage<1) currpage=1;
        if(currpage>pagecount) currpage = pagecount;
        System.out.printf("当前%d页，共%d页，每页%d条，共%d条\n\n",currpage,pagecount,size,recordcount);


        int start = currpage*size-size;
        List<Book> p1 = sdao.page(start,size);
//System.out.println(p1.size());
        for(Book st : p1){
            System.out.println(st.getName());
        }
    }


}
